#define _CRT_SECURE_NO_WARNINGS
#include "12.6_hs.h"

void menu()
{
	printf("*****<--- menu --->*****\n");
	printf("**** 1.Add    2.Sub ****\n");
	printf("**** 3.Mul    4.Div ****\n");
	printf("******** 0.exit ********\n");
}

int Add(int n, int m)
{
	return n + m;
}

int Sub(int n, int m)
{
	return n - m;
}

int Mul(int n, int m)
{
	return n * m;
}

int Div(int n, int m)
{
	return n / m;
}

void Print_stu(struct stu* p, int sz)
{
	for (int i = 0; i < sz; i++)
	{
		printf("%s %s %d\n", p[i].name, p[i].sex, p[i].age);
	}
	printf("\n");
}

int cmp_stu_name_desc(const void* e1, const void* e2)
{
	return strcmp(((struct stu*)e2)->name, ((struct stu*)e1)->name);
}

void Swap(char* e1, char* e2, int width)
{
	for (int i = 0; i < width; i++)
	{
		char t = *(e1 + i);
		*(e1 + i) = *(e2 + i);
		*(e2 + i) = t;
	}
}

void mppx_qsort(const void* base, size_t sz, size_t width, int(*cmp)(const void*, const void*))
{
	for (int n = 0; n < sz - 1; n++)
	{
		int flag = 1;
		for (int j = 0; j < sz - 1 - n; j++)
		{
			if (cmp((char*)base+j * width, (char*)base + (j+1)*width) > 0)
			{
				flag = 0;
				Swap((char*)base + j * width, (char*)base + (j + 1) * width, width);
			}
		}
		if (flag == 1)
		{
			break;
		}
	}
}